<?php
//生成验证码(二)
header("content-type:image/jpeg;");
session_start();
$image=imagecreate(300, 100);
imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$int1=mt_rand(0, 9);
$int2=mt_rand(0, 9);
$int3=mt_rand(0, 9);
$int4=mt_rand(0, 9);
$verify=$int1.$int2.$int3.$int4;
$_SESSION['verify']=$verify;
$fontfile="C:/Windows/Fonts/simhei.ttf";
$color1=imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$color2=imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$color3=imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$color4=imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagettftext($image, mt_rand(48, 68), mt_rand(-30, 30), 60, mt_rand(50, 80), $color1, $fontfile, "$int1");
imagettftext($image, mt_rand(48, 68), mt_rand(-30, 30), 120, mt_rand(50, 80), $color2, $fontfile, "$int2");
imagettftext($image, mt_rand(48, 68), mt_rand(-30, 30), 180, mt_rand(50, 80), $color3, $fontfile, "$int3");
imagettftext($image, mt_rand(48, 68), mt_rand(-30, 30), 240, mt_rand(50, 80), $color4, $fontfile, "$int4");
for($i=0;$i<50;$i++){
	$color=imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
	imageline($image, mt_rand(0, 9)*$i, mt_rand(0, 9)*$i, mt_rand(0, 300)*$i, mt_rand(0, 80)*$i, $color);
	imagesetpixel($image, mt_rand(0, 300), mt_rand(0, 100), $color1);
}
imagejpeg($image);
imagedestroy($image);

